﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DelonixRegiaHMSys.Core.Models;
using DelonixRegiaHMSys.Core.Services;
using DelonixRegiaHMSys.Infrastructure.Data;

namespace DelonixRegiaHMSys.UI.WebForms
{
    public partial class AddStaff : System.Web.UI.Page
    {
        string userID;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                userID = Request.QueryString["UserID"];
                string ID = "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
                string strid = "";
                Random rnd = new Random();
                for (int i = 0; i <= 3; i++)
                {
                    int randomint = rnd.Next(0, ID.Length - 1);
                    strid += ID.Substring(randomint, 2);
                }
                StaffID.Text = strid;
            }
        }

        protected void Addbtn_Click(object sender, EventArgs e)
        {



            Staff st = new Staff();
            st.StaffID = StaffID.Text;
            st.StaffLastName = LastName.Text;
            st.StaffFirstName = FirstName.Text;
            st.DateOfBirth = Convert.ToDateTime(DOBtbx.Text);
            st.BankAccNum = BankAcc.Text;
            st.HomeAddress = Add.Text;
            st.PhoneNum = Convert.ToInt32(PhoneNo.Text);
            st.DutiesName = Duties.SelectedValue;

            var sservice = new stServices(new EfStaffQuery());
            sservice.AddStaff(st);

            Server.Transfer("~/WebForms/HousekeepingandStaffModule/StaffManagement.aspx?UserID=" + userID);
        }
    }
}